#ifndef _LZ77_H
#define _LZ77_H

#include <stdint.h>
#include <stdlib.h>
#include "cWindowBuffer.h"

#define WINBUF_LIST	0

#if WINBUF_LIST
#include "List.h"
#endif

struct lz77_code
{
  uint16_t backward_distance;
  uint8_t lenght;
  uint8_t literal;
};

class cLZ77 
{
  public:
    cLZ77(int window_size,int buffer_size);
    ~cLZ77();
    void Clear();
    bool Encode(uint8_t val,lz77_code * code);

    bool Decode(lz77_code * code,cWindowBuffer * buff);
    bool Flush(lz77_code * code);

  private:    
    int get_back_dist(int index);
    
    int cur_pos;    
    cWindowBuffer winbuf;
#if WINBUF_LIST
    void flush_buffer(lz77_code * code,uint8_t val);
    bool FlushL(lz77_code * code);
    bool EncodeL(uint8_t val,lz77_code * code);
    int get_back_distL(int index);
    List<uint8_t> window;
    List<uint8_t> buffer;
    Iterator<uint8_t> witr;
    Iterator<uint8_t> bitr;
#endif //WINBUF_LIST    

};

#endif //_LZ77_H